package com.example.flower_shop.controller.usr;

import com.example.flower_shop.service.usr.UserService;
import com.example.flower_shop.vo.auth.AuthRespVO;
import com.example.flower_shop.vo.user.*;
import com.example.flower_shop.vo.usr.CodeReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * 用户
 */
@Tag(name = "用户中心接口")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @Operation(summary = "登录", method = "POST",
            requestBody = @RequestBody(
                    content = @Content(mediaType = "application/x-www-form-urlencoded",
                            schema = @Schema(requiredProperties = {
                                    "username", "password"
                            }, implementation = UserLogReqVO.class))
            ))
    public AuthRespVO login(@Valid UserLogReqVO reqVO) {
        return userService.login(reqVO);
    }

    @PostMapping("/register")
    @Operation(summary = "注册", method = "POST")
    public void register(@Valid UserRegReqVO reqVO) {
        userService.register(reqVO);
    }

    @PostMapping("/forget")
    @Operation(summary = "忘记密码", method = "POST")
    public void forget(@Valid ForgetPwdReq req) {
        userService.forgetPwd(req);
    }

    @PostMapping("/reset")
    @Operation(summary = "修改密码", method = "POST")
    public void resetPassword(@Valid ResetPwdReq req) {
        userService.resetPwd(req);
    }

    @PutMapping()
    @Operation(summary = "更新用户信息", method = "PUT")
    public void update(@Valid UserReqVO reqVO) {
        userService.updateUserInfo(reqVO);
    }

    @GetMapping
    @Operation(summary = "获取当前用户信息", method = "GET")
    public UserRespVO getInfo() {
        return userService.getCurrentUserInfo();
    }

    @GetMapping("/loginOut")
    @Operation(summary = "退出登录", method = "GET")
    public void loginOut() {

    }

    @GetMapping("/code")
    @Operation(summary = "获取验证码", method = "GET")
    public void getCode(@Valid CodeReq req) {
        userService.getCode(req);
    }

}
